// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import store from './store'
import util from 'util'
import { Upload, ColorPicker } from 'element-ui';
import simulateLogin from './simulate/login.js'
/* 引入iview组件库 */
import iView from 'iview';

import './assets/css/index.less'
import ExtraModal from './components/common/modal'
// import the component
import Treeselect from '@riophae/vue-treeselect'
// import the styles
import '@riophae/vue-treeselect/dist/vue-treeselect.css'
import widgets from '@/pages/ui-editor/form-item-render/widgets/index';

Vue.use(iView);
Vue.use(Upload);
Vue.use(ColorPicker);
Vue.config.productionTip = false

Vue.directive('permiss', {
  inserted: function(el, binding) {
    if (!util.permiss.judgetPermiss(binding.value)) {
      el.parentNode.removeChild(el);
    }
  }
});
/* 全局过滤器 */
Vue.filter('date', function(value) {
	return util.util.formatDate(value);
});
Vue.filter('time', function(value) {
	return util.util.formatDates(value);
});
Vue.filter('text', function(value) {
  if (value != null && value != '') {
    return value;
  } else {
    return '-';
  }
});
Vue.filter('status', function(value) {
  if (value != null && value != '') {
    if (value == 0) {
      return '禁用';
    }
    if (value == 1) {
      return '启用';
    }
  }
  return "-";
});
Vue.filter('abbreviate', function(value) {
  return util.util.abbreviate(value);
});

Vue.prototype.$Message.config({
  top: 30,
  duration: 3
});

//替换Modal
Vue.prototype.$Modal = ExtraModal;
Vue.component('Modal', ExtraModal);
Vue.component('Treeselect', Treeselect)
for (let i = 0; i < widgets.length; i++) {
  Vue.component(widgets[i].name, widgets[i])
}

/* eslint-disable no-new */
// new Vue({
//     el: '#app',
//     router,
//     components: { App },
//     store,
//     template: '<App/>',
// })


//模拟登录
simulateLogin()
  .then(() => {
    new Vue({
      el: '#app',
      router,
      components: { App },
      store,
      template: '<App/>',
    })
  })
  .catch(() => {})
